package com.bachongLightNovel.works.config;

import com.bachongLightNovel.constant.RabbitmqConstant;
import org.bouncycastle.pqc.crypto.newhope.NHOtherInfoGenerator;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author vermouth
 */

@Configuration
public class RabbitmqConfig {

    public static final String BACHONG_NOVEL_EXCHANGE="BACHONG_NOVEL_EXCHANGE";
    public static final String BACHONG_NOVEL_DELETE_QUEUE="BACHONG_NOVEL_DELETE_QUEUE";
    public static final String BACHONG_NOVEL_DELETE_KEY="BACHONG_NOVEL_DELETE_KEY";


    //声明交换机
    @Bean
    public DirectExchange novelExchange(){
        return new DirectExchange(BACHONG_NOVEL_EXCHANGE,true,false);
    }

    //声明队列
    @Bean
    public Queue novelDeleteQueue(){
        return QueueBuilder.durable(BACHONG_NOVEL_DELETE_QUEUE).build();
    }

    //绑定交换机与队列
    @Bean
    public Binding bindingNovelDirect(Queue novelDeleteQueue,DirectExchange novelExchange){
        return BindingBuilder
                .bind(novelDeleteQueue)
                .to(novelExchange)
                .with(BACHONG_NOVEL_DELETE_KEY);
    }

    //声明小说收藏消息队列
    @Bean
    public Queue collectQueue(){
        return QueueBuilder
                .durable(RabbitmqConstant.BACHONG_NOVEL_COLLECT_QUEUE)
                .build();
    }

    //绑定交换机和消息队列
    @Bean
    public Binding bindingCollectDirect(Queue collectQueue,DirectExchange novelExchange){
        return BindingBuilder
                .bind(collectQueue)
                .to(novelExchange)
                .with(RabbitmqConstant.BACHONG_NOVEL_COLLECT_KEY);
    }
}
